﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using blackhouse.Payments.View;

namespace blackhouse.Payments.Presenter {
    public class NegativePresenter {

        #region Fields

        private INegativeView view;
        private PaymentTransaction paymentTransaction;
        private PaymentError paymentError;

        #endregion

        #region Constructors

        public NegativePresenter(INegativeView view) {
            this.view = view;
        }

        #endregion

        #region Methods

        public void BindView() {
            int posId = this.view.GetRequestPosId();
            int errorId = this.view.GetRequestErrorId();
            string transactionSession = this.view.GetTranSessionId();
            this.paymentTransaction = PaymentTransaction.Find(posId, transactionSession);
            this.paymentError = new PaymentError(errorId);
            if (this.paymentTransaction != null && paymentError.Exist)
                this.paymentTransaction.LogError(this.paymentError);

            this.SetView();
        }

        private void SetView() {
            this.view.ErrorCodeText = this.paymentError.ErrorCode.ToString();
            this.view.ErrorDescriptionText = this.paymentError.ErrorDescription;
        }

        #endregion

    }
}